﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace QuadRemote.Core
{
    public class StorageReader : BinaryReader
    {
        public StorageReader(String name) : base(new GZipStream(new FileStream(name,FileMode.Open),CompressionMode.Decompress))
        {

        }

        public StorageMarker readMarker()
        {
            byte b = this.ReadByte();
            return (StorageMarker)b;
        }

        public void ignore(StorageMarker marker)
        {
            switch (marker)
            {
                case StorageMarker.LIST_ARRAY:
                    int i = ReadInt32();
                    while (i > 0)
                    {
                        ReadByte();
                        i--;
                    }
                    break;
                case StorageMarker.LIST_INT:
                    ReadInt32();
                    break;
                case StorageMarker.LIST_STRING:
                    ReadString();
                    break;
                case StorageMarker.LIST_BOOL:
                    ReadBoolean();
                    break;
                case StorageMarker.LIST_BEGIN:
                    StorageMarker m = readMarker();
                    while (m != StorageMarker.LIST_END)
                    {
                        ReadString();
                        ignore(m);
                        m = readMarker();
                    }
                    break;
            }
        }

    }
}
